In [ ]:
import random #This code imports a random libaray with random numbers
integer = random.randint(1,1000) #Allows the computer to choose a random number between 1 and 1000
print("This is a Number Guess game! Guess a number between 0 and 1000.") #A printed statement for the user to know how to play the game and the range of numbers to choose from
def game():#Defining a variable, game, so I am able to run the program
integer = random.randint(1,1000) #Making the variable integer equal to a random number between 1 and 1000
chances = 10 #Make the variable chances equal to 10, so the user has 10 chances to guess the number
while chances >= 1: #Making the chances greater than or equal to 1 in a while loop, so the program runs constantly if the chances are left
choice = int(input("Enter a Number: ")) #The users choice with an input so the computer knows
if integer == choice: #If the computer's number is equal to the users number
print("Good Job! You have guessed the correct number.") #A printed statement that the user guessed the correct number
break #Ending the while loop
elif integer >= choice: #If the computers number is greater than the users number choice
chances = chances -1 #The user loss 1 chance because they guessed it incorrectly
print("Guess a Higher Number!") #A hint for the user in order to make a better guess
print("You guessed the wrong number.") #Telling the user that their choice was wrong
if chances == 0: #If the user has 0 chances left and guessed incorrectly
print("The number I was thinking of was",integer,"!\n") #A printed statement for the user to know the number the computer chose.
elif integer <= choice: #If the computer's number is less than the users choice
chances = chances - 1 #The user loses 1 chance because they guessed it incorrectly
print("Guess a Lower Number!") #A hint telling the user to guess a lower number for a better chance of guessing it correct
print("You guessed the wrong number.") #Telling the user their choice was wrong
if chances == 0:#If the user has 0 chances left
print("The number I was thinking of was",integer,"!\n") #A printed statement telling the user the correct number
while True: #While loop that repeats the code inside
def end_game(): #Defining a variable that will end the game
keepGoing = input("Do you want to play this game again? Yes or No: ") #Asking if the user will or will not want to play again
if keepGoing == "Yes" or keepGoing == "yes": #If the user's choice is yes or Yes, which are the available inputs
integer = random.randint(1,1000) #The code will run again and the integer will be between 1 to 1000
match = 1 #The match of the game is 1
match += 1 #Adding another number to the match since it increases
print("This is match {match}!".format(match=match)) #Printed statement telling the user that this is the 2nd match
print("This is a Number Guess game! Guess a number between 0 and 1000.") #Printed statement of the instructions to the game
game() #Calling the game function so the game is played again
elif keepGoing == "No" or keepGoing == "no": #If the input of the user is no or No
input("Ok, Have a Good Day! Press enter to exit!") #The game will tell the user to press enter and exit the game
game()#Calling the game function if played again
end_game() #Calling the end_game function to end the game or continue playing based on the users input
break #Ending the while loop based on the users input.
This is a Number Guess game! Guess a number between 0 and 1000. Enter a Number: 500 Guess a Lower Number! You guessed the wrong number. Enter a Number: 350 Guess a Lower Number! You guessed the wrong number. Enter a Number: 200 Guess a Lower Number! You guessed the wrong number. Enter a Number: 100 Guess a Higher Number! You guessed the wrong number. Enter a Number: 150 Guess a Lower Number! You guessed the wrong number. Enter a Number: 120 Guess a Lower Number! You guessed the wrong number. Enter a Number: 110 Guess a Lower Number! You guessed the wrong number. Enter a Number: 105 Guess a Higher Number! You guessed the wrong number. Enter a Number: 106 Guess a Higher Number! You guessed the wrong number. Enter a Number: 107 Guess a Higher Number! You guessed the wrong number. The number I was thinking of was 108 ! Do you want to play this game again? Yes or No: yes This is match 2! This is a Number Guess game! Guess a number between 0 and 1000.
In [ ]:
In [ ]:
In [3]:
import random #This code imports a random libaray with random numbers
points = 0 #Counts the users score every time they get it correct
def game():#Defining a variable, game, so I am able to run the program
global points #The global command allows the program to keep track of the points and the score globally, so throughout the program
integer = random.randint(1,1000) #Making the variable integer equal to a random number between 1 and 1000
chances = 0 #Make the variable chances equal to 0, so the user has 10 chances to guess the number as they guess
while chances < 10: #The amount of chances the user gets to guess the number throughout the game
choice = int(input("This is the Number Guessing Game. Guess a number between 1 and 1000: ")) #Users guess of the number the choose
chances += 1 #The chances increases as the user guesses the number
if choice < integer: #The users number guess compared to the computers number, which is the computers choice greater than the users choice
print("Guess a Higher Number!!") #Printed statement for the user as a hint for the user to guess a higher number
elif choice > integer: #The users number guess greater than the computers integer
print("Guess a Lower Number!!") #Printed statement for the user as a hint for the user to guess a lower number
else: #If the statements above are not true than the bottom statement must be true
print("Correct!") #Printed statement telling the user they have guessed the correct number
score += 1 #User getting a point(s) as they guess the number correctly
print("Your score is:", points) #A printed statement telling the user their score
break #Ending the while loop as the main part if the program ends
if chances == 10: #If the user was not able to guess the correct number and the chances are equal to 10 then they have lost
print("You guessed incorrectly. The number was", integer) #A printed statement telling the user what the computer's integer was
keepGoing = input("Do you want to play again? Yes or No: ") #Allowing the user to play again or end the game
if keepGoing.lower() == "yes": #If the user chooses yes as their input
print("Yes! Let's play another round!") #The user will play another round
game() #The function game is called for the user to play the game again
if keepGoing.lower() == "no": #If the user chooses no as their input
print("Bye, Have a Good Day!") #A printed statement for the user to know that the program ended
game() #The function game is called again as the program ends
This is the Number Guessing Game. Guess a number between 1 and 1000: 500 Guess a Lower Number!! This is the Number Guessing Game. Guess a number between 1 and 1000: 400 Guess a Lower Number!! This is the Number Guessing Game. Guess a number between 1 and 1000: 300 Guess a Higher Number!! This is the Number Guessing Game. Guess a number between 1 and 1000: 350 Guess a Lower Number!! This is the Number Guessing Game. Guess a number between 1 and 1000: 340 Guess a Lower Number!! This is the Number Guessing Game. Guess a number between 1 and 1000: 330 Guess a Lower Number!! This is the Number Guessing Game. Guess a number between 1 and 1000: 320 Guess a Lower Number!! This is the Number Guessing Game. Guess a number between 1 and 1000: 310 Guess a Higher Number!! This is the Number Guessing Game. Guess a number between 1 and 1000: 315 Guess a Higher Number!! This is the Number Guessing Game. Guess a number between 1 and 1000: 317 Correct! Your score is: 1 Do you want to play again? Yes or No: yes Yes! Let's play another round! This is the Number Guessing Game. Guess a number between 1 and 1000: 500 Guess a Higher Number!! This is the Number Guessing Game. Guess a number between 1 and 1000: 600 Guess a Lower Number!! This is the Number Guessing Game. Guess a number between 1 and 1000: 550 Guess a Higher Number!! This is the Number Guessing Game. Guess a number between 1 and 1000: 560 Guess a Higher Number!! This is the Number Guessing Game. Guess a number between 1 and 1000: 570 Guess a Lower Number!! This is the Number Guessing Game. Guess a number between 1 and 1000: 565 Guess a Higher Number!! This is the Number Guessing Game. Guess a number between 1 and 1000: 566 Guess a Higher Number!! This is the Number Guessing Game. Guess a number between 1 and 1000: 567 Guess a Higher Number!! This is the Number Guessing Game. Guess a number between 1 and 1000: 568 Guess a Higher Number!! This is the Number Guessing Game. Guess a number between 1 and 1000: 569 Correct! Your score is: 2 Do you want to play again? Yes or No: no Bye, Have a Good Day!
In [ ]: